@extends('layout.master')

@section('title','帖子列表')

@section('css')
    @parent
    <!-- Daterange picker plugins css -->
    <link href="{{ asset('plugins/bower_components/bootstrap-daterangepicker/daterangepicker.css') }}" rel="stylesheet">
@endsection
@section('main')

    <div class="modal fade" id="btn-hot" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel1">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="exampleModalLabel1">加精</h4>
                </div>
                <div class="modal-body">
                    <form class="floating-labels role-edit">
                        <input id="id-jj" name="id" type="hidden" value="">
                        <fieldset style="border:0;">

                            <div class="form-group m-b-40 m-t-10">
                                <p for="title-modify">加精时间<span style="color:red;font-size: smaller">*即时加精填1</span></p>
                                <input type="text" class="form-control" id="jjtime-modify" name="jjtime"
                                       placeholder="2019-01-15 12:12:12" required><span
                                        class="highlight"></span> <span class="bar"></span>

                            </div>
                            <div class="form-actions">
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="row">
                                            <div class="col-md-offset-3 col-md-9">
                                                <button type="button" class="btn btn-default" data-dismiss="modal">取消
                                                </button>
                                                {!! csrf_field() !!}
                                                <button type="submit" class="btn btn-success" id="btn-jj"><i
                                                            class="fa fa-check"></i> 保存
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </fieldset>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="btn-del" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel1">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="exampleModalLabel1">删除</h4>
                </div>
                <div class="modal-body">
                    <form class="floating-labels role-edit">
                        <input id="id-del" name="id" type="hidden" value="">
                        <fieldset style="border:0;">

                            <div class="form-group m-b-40 m-t-10">
                                <p>系统消息</p>
                                <input type="text" class="form-control" id="messgae-del" name="message_del"><span
                                        class="highlight"></span> <span class="bar"></span>

                            </div>
                            <div class="form-actions">
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="row">
                                            <div class="col-md-offset-3 col-md-9">
                                                <button type="button" class="btn btn-default" data-dismiss="modal">取消
                                                </button>
                                                {!! csrf_field() !!}
                                                <button type="submit" class="btn btn-success" id="btn-delete"><i
                                                            class="fa fa-check"></i> 保存
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </fieldset>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="btn-all-del" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel1">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="exampleModalLabel1">全部删除</h4>
                </div>
                <div class="modal-body">
                    <form class="floating-labels role-edit">
                        <fieldset style="border:0;">

                            <div class="form-group m-b-40 m-t-10">
                                <p>系统消息</p>
                                <input type="text" class="form-control" id="messgae-del-all"
                                       name="message_del_all"><span
                                        class="highlight"></span> <span class="bar"></span>

                            </div>
                            <div class="form-actions">
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="row">
                                            <div class="col-md-offset-3 col-md-9">
                                                <button type="button" class="btn btn-default" data-dismiss="modal">取消
                                                </button>
                                                {!! csrf_field() !!}
                                                <button type="submit" class="btn btn-success" id="btn-all-delete"><i
                                                            class="fa fa-check"></i> 保存
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </fieldset>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <div class="panel">
        <div class="panel-wrapper collapse in" aria-expanded="true">
            <div class="panel-body">
                <form action="#">
                    <div class="form-body">
                        <div class="row">

                            <div class="col-md-3 col-sm-6">
                                <div class="form-group">
                                    <label class="control-label">帖子标题</label>
                                    <input type="text" id="id" class="column_filter form-control"
                                           data-column="0"
                                           name="id" placeholder="帖子标题">
                                </div>
                            </div>
                            <div class="col-md-3 col-sm-6">
                                <div class="form-group">
                                    <label class="control-label">发帖人</label>
                                    <input type="text" id="uid" class="column_filter form-control"
                                           data-column="1"
                                           name="uid" placeholder="发帖人">
                                </div>
                            </div>
                            <div class="col-md-3 col-sm-6">
                                <div class="form-group">
                                    <label class="control-label">发帖时间</label>
                                    <div class="example">
                                        <input class="column_filter form-control input-daterange-datepicker" type="text"
                                               data-column="2" name="time"/>
                                    </div>
                                </div>
                            </div>
                            <div class="col-xs-3 col-md-3">
                                <div class="form-group">
                                    <label for="status">状态</label>
                                    <select class="form-control column_filter"
                                            data-column="3">
                                        <option value="a">全部</option>
                                        <option value="1">显示中</option>
                                        <option value="2">待显示</option>
                                        <option value="3">已删除</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <div class="panel">
        <div class="panel-heading">帖子列表</div>
        <div class="panel-wrapper collapse in" aria-expanded="true">
            <div class="panel-action" style="margin-top: -9px">
                <button class="popup-with-form btn fcbtn btn btn-outline btn-info btn-1c all-jj">
                    <span>批量加精</span>
                </button>
                <button class="popup-with-form btn fcbtn btn btn-outline btn-info btn-1c all-qjj">
                    <span>批量取消加精</span>
                </button>
                <button class='popup-with-form btn fcbtn btn btn-outline btn-info btn-1c' data-toggle='modal'
                        data-target='#btn-all-del'>批量删除
                </button>
                {{--<button class="popup-with-form btn fcbtn btn btn-outline btn-info btn-1c all-del">--}}
                {{--<span>批量删除</span>--}}
                {{--</button>--}}
            </div>
            <div class="panel-body">
                <div class="table-responsive">
                    <table id="example23" class="display nowrap" cellspacing="0" width="100%"
                           data-url="{{ url(request()->getUri()) }}">
                        <thead>
                        <tr>
                            <th></th>
                            <th>帖子ID</th>
                            <th>科室</th>
                            <th>城市</th>
                            <th>标题</th>
                            <th>是否精品</th>
                            <th>发帖人</th>
                            <th>发布时间</th>
                            <th>回帖</th>
                        </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
@endsection
@section('js')
    @parent
    <!-- Plugin JavaScript -->
    <script src="{{ asset('plugins/bower_components/moment/moment.js') }}"></script>
    <!-- Date range Plugin JavaScript -->
    <script src="{{ asset('plugins/bower_components/bootstrap-daterangepicker/daterangepicker.js') }}"></script>
    <script src="{{ asset('plugins/bower_components/Magnific-Popup-master/dist/jquery.magnific-popup.min.js') }}"></script>
    <script src="{{ asset('plugins/bower_components/Magnific-Popup-master/dist/jquery.magnific-popup-init.js') }}"></script>


    <script>
        $('.input-daterange-datepicker').daterangepicker({});
    </script>
    <script src="{{ asset('js/myself.js') }}"></script>
    <script>
        //点击回帖重定向
        obj.on('click', '.btn-post', function () {
            var id = $(this).data('id');
            window.location.href = '/postings/detail/' + id + '/1';
        });


        //删除帖子
        obj.on('click', '.btn-del', function () {
            var id = $(this).data('id');
            var _this = $(this);
            swal({
                    title: "",
                    text: "确定删除吗？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/posting/del/' + id,
                        type: 'POST',
                        error: function (e) {
                            if (e.readyState === 4 && e.status === 422) {
                                for (var i in e.responseJSON) {
                                    if (e.responseJSON[i] !== 'The given data was invalid.') {
                                        err = e.responseJSON[i];
                                        for (var j in err) {
                                            toasterror(err[j][0]);
                                        }
                                    }
                                }
                            }
                        },
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    _this.parent().parent().text('');
                                });
                            }
                        }
                    })
                }
            );
        });


        //加精
        obj.on('click', '.btn-jj', function () {
            var id = $(this).data('id');
            swal({
                    title: "",
                    text: "确定加精吗？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/posting/jj/' + id,
                        type: 'POST',
                        error: function (e) {
                            if (e.readyState === 4 && e.status === 422) {
                                for (var i in e.responseJSON) {
                                    if (e.responseJSON[i] !== 'The given data was invalid.') {
                                        err = e.responseJSON[i];
                                        for (var j in err) {
                                            toasterror(err[j][0]);
                                        }
                                    }
                                }
                            }
                        },
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    $('.hot' + id).text('精品');
                                    $('.btn-hot' + id).html("<button class='btn btn-success btn-qjj' data-id=" + id + ">取消加精</button>");
                                });
                            }
                        }
                    })
                }
            );
        });

        //取消加精
        obj.on('click', '.btn-qjj', function () {
            var id = $(this).data('id');
            swal({
                    title: "",
                    text: "确定取消加精吗？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/posting/qjj/' + id,
                        type: 'POST',
                        error: function (e) {
                            if (e.readyState === 4 && e.status === 422) {
                                for (var i in e.responseJSON) {
                                    if (e.responseJSON[i] !== 'The given data was invalid.') {
                                        err = e.responseJSON[i];
                                        for (var j in err) {
                                            toasterror(err[j][0]);
                                        }
                                    }
                                }
                            }
                        },
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    $('.hot' + id).text('非精品');
                                    // $('.btn-hot' + id).html("<button class='btn btn-success btn-jj' data-id=" + id + ">加精</button>");
                                    $('.btn-hot' + id).html("<button  class='btn btn-info'  onclick='hot(" + id + ")' data-toggle='modal' data-target='#btn-hot' >加精</button>");
                                });
                            }
                        }
                    })
                }
            );
        });
        //撤销
        obj.on('click', '.btn-cancle', function () {
            var id = $(this).data('id');
            var _this = $(this);
            swal({
                    title: "",
                    text: "确定撤销吗？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/posting/cancle/' + id,
                        type: 'POST',
                        error: function (e) {
                            if (e.readyState === 4 && e.status === 422) {
                                for (var i in e.responseJSON) {
                                    if (e.responseJSON[i] !== 'The given data was invalid.') {
                                        err = e.responseJSON[i];
                                        for (var j in err) {
                                            toasterror(err[j][0]);
                                        }
                                    }
                                }
                            }
                        },
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    _this.parent().parent().text('');
                                });
                            }
                        }
                    })
                }
            );
        });

        $(".all-jj").click(function (e) {
            e.preventDefault();
            //复选框
            var ids = [];
            var checks = document.getElementsByClassName("check");

            for (var i = 0; i < checks.length; i++) {
                var _this = checks[i];
                if (_this.checked === true) {
                    ids[i] = _this.dataset.id;
                }
            }
            if (ids.length <= 0) {
                swal('你倒是选啊~~');
                return false;
            }

            swal({
                    title: "",
                    text: "确定加精吗？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/posting/alljj',
                        type: 'POST',
                        data: {ids: ids},
                        error: function (e) {
                            if (e.readyState === 4 && e.status === 422) {
                                for (var i in e.responseJSON) {
                                    if (e.responseJSON[i] !== 'The given data was invalid.') {
                                        err = e.responseJSON[i];
                                        for (var j in err) {
                                            toasterror(err[j][0]);
                                        }
                                    }
                                }
                            }
                        },
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    for (var j = 0; j < ids.length; j++) {
                                        $('.hot' + ids[j]).text('精品');
                                        $('.btn-hot' + ids[j]).html("<button class='btn btn-success btn-qjj' data-id=" + ids[j] + ">取消加精</button>");
                                        checks[j].checked = false;
                                    }

                                });
                            }
                        }
                    })
                }
            );
        });

        $(".all-qjj").click(function (e) {
            e.preventDefault();
            //复选框
            var ids = [];
            var checks = document.getElementsByClassName("check");

            for (var i = 0; i < checks.length; i++) {
                var _this = checks[i];
                if (_this.checked === true) {
                    ids[i] = _this.dataset.id;
                }
            }
            if (ids.length <= 0) {
                swal('你倒是选啊~~');
                return false;
            }

            swal({
                    title: "",
                    text: "确定取消加精吗？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/posting/allqjj',
                        type: 'POST',
                        data: {ids: ids},
                        error: function (e) {
                            if (e.readyState === 4 && e.status === 422) {
                                for (var i in e.responseJSON) {
                                    if (e.responseJSON[i] !== 'The given data was invalid.') {
                                        err = e.responseJSON[i];
                                        for (var j in err) {
                                            toasterror(err[j][0]);
                                        }
                                    }
                                }
                            }
                        },
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    for (var j = 0; j < ids.length; j++) {
                                        $('.hot' + ids[j]).text('非精品');
                                        $('.btn-hot' + ids[j]).html("<button class='btn btn-success btn-jj' data-id=" + ids[j] + ">加精</button>");
                                        // $("#check" + ids[j]).remove(checked);
                                        checks[j].checked = false;
                                    }

                                });
                            }
                        }
                    })
                }
            );
        });

        $("#btn-all-delete").click(function (e) {
            e.preventDefault();
            //复选框
            var ids = [];
            var checks = document.getElementsByClassName("check");
            var message = $("#messgae-del-all").val();

            for (var i = 0; i < checks.length; i++) {
                var _this = checks[i];
                if (_this.checked === true) {
                    ids[i] = _this.dataset.id;
                }
            }
            if (ids.length <= 0) {
                swal('你倒是选啊~~');
                return false;
            }

            swal({
                    title: "",
                    text: "确定删除吗？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/posting/alldel',
                        type: 'POST',
                        data: {ids: ids, message: message},
                        error: function (e) {
                            if (e.readyState === 4 && e.status === 422) {
                                for (var i in e.responseJSON) {
                                    if (e.responseJSON[i] !== 'The given data was invalid.') {
                                        err = e.responseJSON[i];
                                        for (var j in err) {
                                            toasterror(err[j][0]);
                                        }
                                    }
                                }
                            }
                        },
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    for (var j = 0; j < ids.length; j++) {
                                        var _that = $(".hot" + ids[j])[0];
                                        $(_that).parent().parent().text('');
                                    }

                                });
                            }
                        }
                    })
                }
            );
        });

        $("#btn-jj").click(function (e) {
            e.preventDefault();
            //复选框
            var id = $("#id-jj").val();
            var time = $("#jjtime-modify").val();

            swal({
                    title: "",
                    text: "确定加精吗？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/posting/jj/' + id,
                        type: 'POST',
                        data: {time: time},
                        error: function (e) {
                            if (e.readyState === 4 && e.status === 422) {
                                for (var i in e.responseJSON) {
                                    if (e.responseJSON[i] !== 'The given data was invalid.') {
                                        err = e.responseJSON[i];
                                        for (var j in err) {
                                            toasterror(err[j][0]);
                                        }
                                    }
                                }
                            }
                        },
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            }
                        }
                    })
                }
            );
        });

        function hot(sid) {
            $("#id-jj").val(sid);
        }

        function del(sid) {
            $("#id-del").val(sid);
        }


        $("#btn-delete").click(function (e) {
            e.preventDefault();
            var id = $("#id-del").val();
            var message = $("#messgae-del").val();

            swal({
                    title: "",
                    text: "确定删除吗？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/posting/del/' + id,
                        type: 'POST',
                        data: {message: message},
                        error: function (e) {
                            if (e.readyState === 4 && e.status === 422) {
                                for (var i in e.responseJSON) {
                                    if (e.responseJSON[i] !== 'The given data was invalid.') {
                                        err = e.responseJSON[i];
                                        for (var j in err) {
                                            toasterror(err[j][0]);
                                        }
                                    }
                                }
                            }
                        },
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    var _that = $(".hot" + id);
                                    $(_that).parent().parent().text('');
                                });
                            }
                        }
                    })
                }
            );
        });

    </script>
@endsection